package provider

import (
	"context"
	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
	"go-pan/internal/storage"
)

type MinIOProvider struct {
	endpoint string
	options  minio.Options
}

func NewMinIOProvider(endpoint string, accessKeyID string, secretAccessKey string, useSSL bool) *MinIOProvider {
	return &MinIOProvider{
		endpoint: endpoint,
		options: minio.Options{
			Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
			Secure: useSSL,
		},
	}
}

func (p *MinIOProvider) GetUserStorage(ctx context.Context, userID string) (storage.Storage, error) {
	cli, err := minio.New(p.endpoint, &p.options)
	if err != nil {
		return nil, err
	}
	minioStorage := storage.NewMinIOStorage(cli)
	return minioStorage, err
}
